package com.alpha.eceasy.mall.controller;

import com.alpha.eceasy.core.R;
import com.alpha.eceasy.mall.api.entity.MallImDetail;
import com.alpha.eceasy.mall.service.impl.MallImDetailServiceImpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 聊天会话详情表 前端控制器
 * </p>
 *
 * @author huangpengfei
 * @since 2024-05-15
 */
@Hidden
@RestController
@RequestMapping("/mall-im-detail")
@Tag(description = "mall-im-detail", name = "聊天会话详情")
public class MallImDetailController {
    @Resource
    private MallImDetailServiceImpl imDetailService;

    /**
     * 分页查询
     *
     * @param page 分页对象
     * @param im   聊天会话详情
     * @return 分页结果
     */
    @Operation(description = "分页查询", summary = "分页查询")
    @GetMapping("")
    public R<IPage<MallImDetail>> page(Page<MallImDetail> page, MallImDetail im) {
        return R.ok(imDetailService.page(page, Wrappers.query(im)));
    }

    /**
     * 通过guid查询聊天会话详情
     *
     * @param guid guid
     * @return R 返回结果 聊天会话详情
     */
    @Operation(description = "通过guid查询", summary = "通过guid查询")
    @GetMapping("/{guid}")
    public R<MallImDetail> getByGuid(@PathVariable("guid") String guid) {
        return R.ok(imDetailService.getByGuid(guid));
    }

    /**
     * 新增聊天会话详情
     *
     * @param entity 聊天会话详情
     * @return R 返回结果 是否成功
     */
    @Operation(description = "新增聊天会话详情", summary = "新增聊天会话详情")
    //@SysLog("新增聊天会话详情")
    @PostMapping
    public R<Boolean> save(@RequestBody MallImDetail entity) {
        return R.ok(imDetailService.save(entity));
    }

    /**
     * 通过guid修改聊天会话详情
     *
     * @param entity 聊天会话详情
     * @return R 返回结果 是否成功
     */
    @Operation(description = "修改聊天会话详情", summary = "修改聊天会话详情")
    //@SysLog("修改聊天会话详情")
    @PutMapping
    public R<Boolean> updateByGuid(@RequestBody MallImDetail entity) {
        return R.ok(imDetailService.updateByGuid(entity));
    }

    /**
     * 通过guid删除聊天会话详情
     *
     * @param guid guid
     * @return R 返回结果
     */
    //@SysLog("通过id删除聊天会话详情")
    @Operation(description = "通过guid删除聊天会话详情", summary = "通过guid删除聊天会话详情")
    @DeleteMapping("/{guid}")
    public R<Boolean> removeById(@PathVariable String guid) {
        return R.ok(imDetailService.removeByGuid(guid));
    }

}
